package com.lm.scau.dyb.view;

import android.util.SparseArray;
import android.view.View;

/**
 * Function:
 * auth：liming on 2016/5/30 14:38
 * mail：liming@wxchina.com
 */
public class ViewHolder {

    /**
     * 万能的viewHolder类
     * @param view
     * @param id
     * @param <T>
     * @return
     */
    public static  <T extends View> T getHolderView(View view, int id) {
        SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
        if (viewHolder == null) {
            viewHolder = new SparseArray<View>();
            view.setTag(viewHolder);
        }
        View childView = viewHolder.get(id);
        if (childView == null) {
            childView = view.findViewById(id);
            viewHolder.put(id, childView);
        }
        return (T) childView;
    }
}
